import React, { PropsWithChildren } from 'react';
import { store, Context } from './constant';
import Executor from './Executor';

export type ProviderProps = PropsWithChildren<{
  models: Record<string, () => unknown>;
}>;
const Provider = (props: ProviderProps) => {
  const { models, children } = props;
  return (
    <Context.Provider value={store}>
      {Object.entries(models).map(([key, hook]) => (
        <Executor key={key} name={key} hook={hook} />
      ))}
      {children}
    </Context.Provider>
  );
};

export default Provider;
